package com.yanqu.road.entity.activity.selectlottery.data;

import com.yanqu.road.entity.DataObject;
import com.yanqu.road.entity.DataStatus;
import com.yanqu.road.entity.FieldTypeAnnotation;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@FieldTypeAnnotation(tableName = "t_u_activity_select_lottery_user_data", desc = "通用自选抽奖-玩家数据表")
public class SelectLotteryUserData extends DataObject {

    @FieldTypeAnnotation(desc = "活动ID", select = true, update = true)
    private int activityId;

    @FieldTypeAnnotation(desc = "玩家ID", select = true, update = true)
    private long userId;

    @FieldTypeAnnotation(desc = "自选奖励配置ID")
    private int selectRewardId;

    @FieldTypeAnnotation(desc = "抽取次数,中二级，一级大奖后归0")
    private int drawNum;

    @FieldTypeAnnotation(desc = "抽取中二级大奖次数，中一级大奖后归0")
    private int seRewardNum;

    @FieldTypeAnnotation(desc = "总抽奖次数")
    private int allDrawNum;

    @FieldTypeAnnotation(desc = "最近进入活动的时间")
    private long lastEnterTime;

    @FieldTypeAnnotation(desc = "自选奖励次数MAP")
    private Map<Integer, Integer> selectNumMap = new ConcurrentHashMap<>();

    @FieldTypeAnnotation(desc = "创建时间")
    private long createTime;

    public SelectLotteryUserData() {
    }

    public SelectLotteryUserData(int activityId, long userId, int drawNum, int seRewardNum) {
        this.activityId = activityId;
        this.userId = userId;
        this.selectRewardId = 0;
        this.drawNum = drawNum;
        this.seRewardNum = seRewardNum;
        this.allDrawNum = 0;
        this.lastEnterTime = System.currentTimeMillis();
        this.createTime = System.currentTimeMillis();
        setInsertOption();
    }

    public int getActivityId() {
        return activityId;
    }
    public void setActivityId(int activityId) {
        if (this.activityId != activityId) {
            this.activityId = activityId;
            setOp(DataStatus.Update);
        }
    }

    public long getUserId() {
        return userId;
    }
    public void setUserId(long userId) {
        if (this.userId != userId) {
            this.userId = userId;
            setOp(DataStatus.Update);
        }
    }

    public int getSelectRewardId() {
        return selectRewardId;
    }
    public void setSelectRewardId(int selectRewardId) {
        if (this.selectRewardId != selectRewardId) {
            this.selectRewardId = selectRewardId;
            setOp(DataStatus.Update);
        }
    }

    public int getDrawNum() {
        return drawNum;
    }

    public void setDrawNum(int drawNum) {
        if (this.drawNum != drawNum) {
            this.drawNum = drawNum;
            setOp(DataStatus.Update);
        }
    }

    public int getSeRewardNum() {
        return seRewardNum;
    }

    public void setSeRewardNum(int seRewardNum) {
        if (this.seRewardNum != seRewardNum) {
            this.seRewardNum = seRewardNum;
            setOp(DataStatus.Update);
        }
    }

    public void addSeRewardNum(int num) {
        this.seRewardNum += num;
        setOp(DataStatus.Update);
    }

    public int getAllDrawNum() {
        return allDrawNum;
    }
    public void setAllDrawNum(int allDrawNum) {
        if (this.allDrawNum != allDrawNum) {
            this.allDrawNum = allDrawNum;
            setOp(DataStatus.Update);
        }
    }

    public long getLastEnterTime() {
        return lastEnterTime;
    }

    public void setLastEnterTime(long lastEnterTime) {
        if (this.lastEnterTime != lastEnterTime) {
            this.lastEnterTime = lastEnterTime;
            setOp(DataStatus.Update);
        }
    }

    public Map<Integer, Integer> getSelectNumMap() {
        return selectNumMap;
    }

    public void setSelectNumMap(Map<Integer, Integer> selectNumMap) {
        if (null == selectNumMap){
            return;
        }
        if (this.selectNumMap == null || !this.selectNumMap.equals(selectNumMap)) {
            this.selectNumMap = selectNumMap;
            setOp(DataStatus.Update);
        }
    }

    public long getCreateTime() {
        return createTime;
    }
    public void setCreateTime(long createTime) {
        if (this.createTime != createTime) {
            this.createTime = createTime;
            setOp(DataStatus.Update);
        }
    }

    /**
     * 添加抽奖次数
     */
    public void addDrawNum(int num) {
        this.drawNum += num;
        this.allDrawNum += num;
        setOp(DataStatus.Update);
    }

    /**
     * 添加自选奖励次数
     * @param selectRewardId
     * @param num
     */
    public void addSelectNum(int selectRewardId, int num) {
        if (selectNumMap.containsKey(selectRewardId)) {
            selectNumMap.put(selectRewardId, selectNumMap.get(selectRewardId) + num);
        } else {
            selectNumMap.put(selectRewardId, num);
        }
        setOp(DataStatus.Update);
    }

    /**
     * 获取自选中过的次数
     * @param selectRewardId
     * @return
     */
    public int getSelectNum(int selectRewardId) {
        if (selectNumMap.containsKey(selectRewardId)) {
            return selectNumMap.get(selectRewardId);
        }
        return 0;
    }
}
